package com.heima.behavior.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.heima.behavior.mapper.BehaviorMapper;
import com.heima.behavior.service.LoadArticleBehaviorService;
import com.heima.model.article.dtos.ArticleBehaviorDto;
import com.heima.model.behavior.pojos.BeBehavior;
import com.heima.model.common.dtos.ResponseResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class LoadArticleBehaviorController {

    @Autowired
    private LoadArticleBehaviorService loadArticleBehaviorService;
    @Autowired
    private BehaviorMapper behaviorMapper;
    @PostMapping("/load_article_behavior")
    public ResponseResult loadArticleBehavior(@RequestBody ArticleBehaviorDto dto){
        return loadArticleBehaviorService.loadArticleBehavior(dto);
    }

    @PostMapping("/behavior")
    public BeBehavior findById(@RequestBody Long articleId, Integer userId){
        LambdaQueryWrapper<BeBehavior> queryWrapper = new LambdaQueryWrapper<BeBehavior>()
                .eq(BeBehavior::getArticleId, articleId)
                .eq(BeBehavior::getUserId, userId);
        return behaviorMapper.selectOne(queryWrapper);
    }
}
